package com.qfedu.service;

import com.qfedu.mapper.UsersMapper;
import com.qfedu.pojo.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UsersServiceImpl implements UserDetailsService {
    @Autowired
    private UsersMapper usersMapper;;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        Users users = usersMapper.selectByUsername(username);
        if (users == null) {
            throw new UsernameNotFoundException("用户名或密码错误");
        }
        return new User(username,users.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }
}
